#ifndef D_LIST_H
#define D_LIST_H

/**
 * d_list.h
 * Asif Shahidullah
 *
 * Prototypes and structs for doubly-linked list. Note: list
 * is 0-index based. All indices are counted from the head.
 *
 * Note, this is a fully implemented doubly-linked list. Some
 * of these functions are never called because they are
 * unecessary.
 */

/* Contains the data_t struct, which has type
 * LData */
#include "list_data.h"

struct list_element_t {
  LData data;
  struct list_element_t *prev;
  struct list_element_t *next;
};
typedef struct list_element_t* Node;

/* This struct stores the head, tail and size
 * of a list */
struct list_t {
  int size;
  Node head;
  Node tail;
};
typedef struct list_t* List;

/* Call this function to create a list, initializing all 
 * values in the List struct. */
List allocate_list(void);

/* Initialize the list with an LData element
 * Returns: 0 on failure
 * 1 on success */
int init_list (List, LData);

/* Traverse list until we reach LData, and return 
 * the index; index 0 is the head. 
 * Returns: -1 on failure
 * index on success */
int get_index (List, LData);

/* Return the data at this index, index is counted
 * from the head.
 * Returns: NULL on failure
 * pointer to LData on success */
LData get (List, int);

/* Insert a node at this index, the element at this index
 * becomes the element after the new node. 
 * Returns: 0 on failure
 * 1 on success */
int insert_node (List, int, LData);

/* Remove the node at this index,
 * Returns: 0 on failure
 * pointer to LData on success */
LData remove_node (List, int);

/* Deinitializes the list, freeing all allocated
 * memory. */
void deinit_list (List);

#endif
